#pragma once
#include "afxcmn.h"

#include "Utils/FastBlockQueue.h"
#include "Business/QueueContext.h"

// for test
#include "Business/ExchangeNotify.h"

class ThreadManager;
class CallAuctionBusiness;
class CallAuctionArgument;
struct Command;

// CCallActionBusinessDlg dialog

class CCallAuctionBusinessDlg : public CDialog
{
	DECLARE_DYNAMIC(CCallAuctionBusinessDlg)

public:
	CCallAuctionBusinessDlg(ThreadManager& threadManager,CWnd* pParent = NULL);   // standard constructor
	virtual ~CCallAuctionBusinessDlg();

// Dialog Data
	enum { IDD = IDD_CALL_AUCTION_BUSINESS_DLG };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual BOOL OnInitDialog();

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnBnClickedButtonAdd();
	afx_msg void OnLvnKeydownCallauctionBusinessList(NMHDR *pNMHDR, LRESULT *pResult);

	afx_msg void OnTimer(UINT_PTR nIDEvent);
	afx_msg void OnMove(int x, int y);

	void HandlerShortcuts(int index, WORD key);

private:
	CallAuctionBusiness* AddBusiness(CallAuctionArgument const& argument);
	void InitBusinessList();
	void InsertBusiness(CallAuctionBusiness* business);
	void UpdateArgument(int index, QueueItem& item);

	int GetCommandType(WORD key);
	void OnCommand(Command const& cmd);
	
	int GetBusinessIndex(CallAuctionBusiness* business) const;
	void UpdateBusinessList(int index, CallAuctionArgument const& argument);

	void Test();

	void PushExchangeStatus(ExchangeStatus::FLAG status);
	void PushPendingMarket(int contract,Direction::TYPE direction,int price,int quantity);

	ThreadManager& m_threadManager;
	FastBlockQueue::FastBlockQueuePtr m_uiQueue;
	QueueContext m_queueContext;

	std::map<CallAuctionBusiness*,int> m_businessIndexMap;

	CListCtrl m_businessList;
protected:
	virtual void OnCancel();
	virtual void OnOK();
};
